package com.jason.bbs.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.jason.bbs.bean.UserInfo;
import com.jason.bbs.bean.UserInfoExample;
import com.jason.bbs.bean.UserInfoExample.Criteria;
import com.jason.bbs.mapper.UserInfoMapper;
import com.jason.bbs.service.UserInfoService;

@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {
	@Resource
	private UserInfoMapper userInfoMapper;

	@Override
	public UserInfo login(UserInfo userInfo) {
		UserInfoExample example = new UserInfoExample();
		Criteria where = example.createCriteria();
		where.andUserNameEqualTo(userInfo.getUserName());
		where.andPasswordEqualTo(
				DigestUtils.md5DigestAsHex((userInfo.getUserName() + userInfo.getPassword()).getBytes()));

		List<UserInfo> list = userInfoMapper.selectByExample(example);
		return list.isEmpty() ? null : list.get(0);
	}

}
